<template>
  <div>
    <div class="main-content">
      <div style="width: 100%">
        <el-form
          :model="searchForm"
          ref="searchFormRef"
          size="mini"
          :inline="true"
        >
          <div>
            <el-form-item label="评价年度起止" prop="startTime">
              <el-date-picker
                v-model="searchForm.startTime"
                align="right"
                type="year"
                placeholder="选择开始年份"
                :picker-options="pickerOptions"
                value-format="yyyy"
                format="yyyy"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>-</el-form-item>
            <el-form-item prop="endTime">
              <el-date-picker
                v-model="searchForm.endTime"
                align="right"
                type="year"
                placeholder="选择结束年份"
                :picker-options="pickerOptions"
                value-format="yyyy"
                format="yyyy"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item>
              <el-button
                type="primary"
                size="mini"
                @click="getQueryCreditStatusInfo"
                >查询</el-button
              >
            </el-form-item>
          </div>
        </el-form>

        <el-table
          :default-sort="{ prop: 'evaluationYear', order: 'descending' }"
          :data="canpanyInfo"
          border
          style="width: 100%"
          v-loading="listLoading"
        >
          <el-table-column prop="evaluationYear" label="评价年度">
          </el-table-column>
          <el-table-column prop="evaluationScore" label="评价得分">
          </el-table-column>
          <el-table-column prop="evaluationResult" label="评价结果">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { queryCreditStatusInfo } from "../../../api/taxAnalysis";
import { getCreditStatusInfo } from "@/api/tax";
import { timeFun } from "../../../utils/date";
export default {
  props: {},
  data() {
    return {
      name: "taxInformation",
      //查询表单
      searchForm: {
        startTime: "",
        endTime: ""
      },

      currentId: "",

      pickerOptions: {
        disabledDate(time) {
          // 获取三年前的今天和昨天的日期
          const threeYearsAgo = new Date();
          threeYearsAgo.setFullYear(threeYearsAgo.getFullYear() - 3);
          threeYearsAgo.setHours(0, 0, 0, 0);

          const yesterday = new Date();
          yesterday.setDate(yesterday.getDate() - 1);
          yesterday.setHours(0, 0, 0, 0);

          // 比较日期是否在三年前的今天和昨天之外
          return (
            time.getTime() < threeYearsAgo.getTime() ||
            time.getTime() > yesterday.getTime()
          );
        }
      },

      listLoading: false,

      canpanyInfo: []
    };
  },
  methods: {
    getList(id, clear) {
      if (!clear) {
        this.searchForm.startTime = "";
        this.searchForm.endTime = "";
      }
      this.currentId = id;
      this.getQueryCreditStatusInfo();
    },

    getQueryCreditStatusInfo() {
      if (this.searchForm.startTime && this.searchForm.endTime) {
        if (!timeFun(this.searchForm.startTime, this.searchForm.endTime)) {
          return this.$message.error("结束时间必须大于开始时间哦");
        }
      } else if (this.searchForm.startTime || this.searchForm.endTime) {
        return this.$message.error("请输入评价年度起止时间");
      }

      this.canpanyInfo = [];
      this.listLoading = true;
      getCreditStatusInfo({
        enterpriseId: this.currentId,
        startTime: this.searchForm.startTime,
        endTime: this.searchForm.endTime
      })
        .then(res => {
          this.canpanyInfo = res.data.creditEvaluationList;
          this.listLoading = false;
        })
        .finally(() => {
          this.listLoading = false;
        });
    }
  }
};
</script>

<style></style>
